package com.xzq.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.xzq.biz.ONPBiz;
import com.xzq.biz.OrdersBiz;
import com.xzq.entity.OrderAndProduct;
import com.xzq.entity.Orders;
import com.xzq.entity.User;
@Controller
public class ONPAction extends BaseAction {
	@Resource
	private ONPBiz onpbiz;
	@Resource
	private OrdersBiz biz;
	private OrderAndProduct onp;

	public OrderAndProduct getOnp() {
		return onp;
	}

	public void setOnp(OrderAndProduct onp) {
		this.onp = onp;
	}
	public String addONP(){
		User user = (User) session.get("user");
		Orders orders = biz.findISHaveShopCat(user);
		if(orders==null){
			orders = new Orders();
			orders.setUser(user);
			int count = biz.addOrders(orders);
		}
		onp.setOrders(orders);
		int count = onpbiz.addONP(onp);
		if(count>0){
			return "index";
		}else{
			return "fail";
		}
	}
}
